﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WX.WMS.DataModel;

namespace WX.WMS.BLL
{
    public class VInStockItemGroup : T_INSTOCK_ITEM
    {
        private string _StoreName;
        private double _PACKET_QTYCount;
        private double _PACKET_QTY2Count;
        private double _NET_WEIGHTCount;
        private double _GROSS_WEIGHTCount;
        private string _ProductCode;
        private string _Standard;
        private string _LotNumber;
        private string _SubLotNumber;
        private string _KeyStandard;
        private string _SupplyLotNumber;
        private string _BigClass;
        private string _UnitName1;
        private string _UnitName2; 

        public string StoreName
        {
            get { return this._StoreName; }
            set { this._StoreName = value; }
        }
        public double PACKET_QTY2Count
        {
            get { return this._PACKET_QTY2Count; }
            set { this._PACKET_QTY2Count = value; }
        }
        public double PACKET_QTYCount
        {
            get { return this._PACKET_QTYCount; }
            set { this._PACKET_QTYCount = value; }
        }
        public double NET_WEIGHTCount
        {
            get { return this._NET_WEIGHTCount; }
            set { this._NET_WEIGHTCount = value; }
        }
        public double GROSS_WEIGHTCount
        {
            get { return this._GROSS_WEIGHTCount; }
            set { this._GROSS_WEIGHTCount = value; }
        }


        public string ProductCode
        {
            get { return this._ProductCode; }
            set
            {
                this._ProductCode = value;
            }
        }

        public string Standard
        {
            get { return this._Standard; }
            set
            {
                this._Standard = value;
            }
        }

        public string LotNumber
        {
            get { return this._LotNumber; }
            set
            {
                this._LotNumber = value;
            }
        }

        public string SubLotNumber
        {
            get { return this._SubLotNumber; }
            set
            {
                this._SubLotNumber = value;
            }
        }
        public string KeyStandard
        {
            get { return this._KeyStandard; }
            set { this._KeyStandard = value; }
        }

        public string SupplyLotNumber
        {
            get { return this._SupplyLotNumber; }
            set { this._SupplyLotNumber = value; }
        }

        public string BigClass
        {
            get { return this._BigClass; }
            set { this._BigClass = value; }
        }
        public string WeightUnitName
        {
            get { return this._UnitName1; }
            set { this._UnitName1 = value; }
        }
        public string PackUnitName
        {
            get { return this._UnitName2; }
            set
            {
                this._UnitName2 = value;
            }
        }
    }
    public class VInStockItem : T_INSTOCK_ITEM
    {
        private string _StockName;
        private string _AreaName;
        private string _FloorName;
        private string _StoreName;
        private string _UnitName1;
        private string _UnitName2;
        private string _ProductCode;
        private string _Standard;
        private string _LotNumber;
        private string _SubLotNumber;
        private string _PacketNum;
        private string _KeyStandard;
        private string _SupplyLotNumber;
        private string _BigClass;
        private string _ClientName;
        private string _ClinetCode;
        private string _Size;
        //private string _CarNO;
        //private string _RawID;

        public string StockName
        {
            get { return _StockName; }
            set { _StockName = value; }
        }
        public string AreaName
        {
            get { return this._AreaName; }
            set { this._AreaName = value; }
        }
        public string FloorName
        {
            get { return this._FloorName; }
            set { this._FloorName = value; }
        }
        public string StoreName
        {
            get { return this._StoreName; }
            set { this._StoreName = value; }
        }
        public string WeightUnitName
        {
            get { return this._UnitName1; }
            set { this._UnitName1 = value; }
        }
        public string PackUnitName
        {
            get { return this._UnitName2; }
            set {
                this._UnitName2 = value;
            }
        }

        public string ProductCode
        {
            get { return this._ProductCode; }
            set
            {
                this._ProductCode = value;
            }
        }

        public string Standard
        {
            get { return this._Standard; }
            set
            {
                this._Standard = value;
            }
        }

        public string LotNumber
        {
            get { return this._LotNumber; }
            set
            {
                this._LotNumber = value;
            }
        }

        public string SubLotNumber
        {
            get { return this._SubLotNumber; }
            set
            {
                this._SubLotNumber = value;
            }
        }
        public string PacketNum
        {
            get { return this._PacketNum; }
            set { this._PacketNum = value; }
        }
        public string KeyStandard
        {
            get { return this._KeyStandard; }
            set { this._KeyStandard = value; }
        }

        public string SupplyLotNumber
        {
            get { return this._SupplyLotNumber; }
            set { this._SupplyLotNumber = value; }
        }

        public string BigClass
        {
            get { return this._BigClass; }
            set { this._BigClass = value; }
        }

        public string ClientName
        {
            get
            {
                return _ClientName;
            }
            set
            {
                _ClientName = value;
            }
        }
        public string ClientCode
        {
            get
            {
                return _ClinetCode;
            }
            set
            {
                _ClinetCode = value;
            }
        }
        public string Size
        {
            get { return this._Size; }
            set { this._Size = value; }
        }
        //public string CarNO
        //{
        //    get
        //    {
        //        return this._CarNO ;
        //    }
        //    set
        //    {
        //        this._CarNO = value;
        //    }
        //}
        //public string RawID
        //{
        //    get
        //    {
        //        return this._RawID ;
        //    }
        //    set
        //    {
        //        this._RawID = value;
        //    }
        //}
    }
    public class VInStock : T_INSTOCK
    {
        private string _ClientName;
        private string _CreateUserName;
        private string _AuditUserName;
        //private string _TypeName;
        private string _ClinetCode;
        public string ClientCode
        {
            get
            {
                return _ClinetCode;
            }
            set
            {
                _ClinetCode = value;
            }
        }
        public string ClientName
        {
            get
            {
                return _ClientName;
            }
            set
            {
                _ClientName = value;
            }
        }
        public string CreateUserName
        {
            get { return _CreateUserName; }
            set
            {
                _CreateUserName = value;
            }
        }
        public string AuditUserName
        {
            get { return _AuditUserName; }
            set { _AuditUserName = value; }
        }
        public string TypeName
        {
            get
            {
                return Enum.GetName(typeof(Enumerations.InStockType), this.TYPE);
            }
        }
    }
    public class ReportBLL : BaseBLL
    {





        //public VInStock GetVInstockByID(string ID)
        //{
        //    T_INSTOCK source = new BaseDAO().T_INSTOCKs.Single(t => t.ID.ToString() == ID);
        //    if (source == null) return null;
        //    VInStock vstock = new VInStock();
        //    vstock.ID = source.ID;
        //    vstock.APPLY_ID = source.APPLY_ID;
        //    vstock.AUDIT_TIME = source.AUDIT_TIME;
        //    vstock.AUDITOR_ID = source.AUDITOR_ID;
        //    vstock.CLIENT_ID = source.CLIENT_ID;
        //    vstock.CREATE_TIME = source.CREATE_TIME;
        //    vstock.CREATOR_ID = source.CREATOR_ID;
        //    vstock.E_ACCOUNT = source.E_ACCOUNT;
        //    vstock.INSTOCK_DATE = source.INSTOCK_DATE;
        //    vstock.INSTOCK_ID = source.INSTOCK_ID;
        //    vstock.SERIAL_NO = source.SERIAL_NO;
        //    vstock.STATUS = source.STATUS;
        //    vstock.TYPE = source.TYPE;
        //    vstock.ClientName = source.T_CLIENT.NAME;
        //    vstock.CreateUserName = source.T_SYS_USER.NAME;
        //    vstock.AuditUserName = source.T_SYS_USER1.NAME;
        //    return vstock;
        //}


        public IEnumerable<VInStock> GetVInstock(string ID)
        {
            var source = from t in new BaseDAO().T_INSTOCKs
                         where t.ID.ToString() == ID
                         select new VInStock
                         {
                             ID = t.ID,
                             APPLY_ID = t.APPLY_ID,
                             AUDIT_TIME = t.AUDIT_TIME,
                             AUDITOR_ID = t.AUDITOR_ID,
                             CLIENT_ID = t.CLIENT_ID,
                             CREATE_TIME = t.CREATE_TIME,
                             CREATOR_ID = t.CREATOR_ID,
                             E_ACCOUNT = t.E_ACCOUNT,
                             INSTOCK_DATE = t.INSTOCK_DATE,
                             INSTOCK_ID = t.INSTOCK_ID,
                             SERIAL_NO = t.SERIAL_NO,
                             STATUS = t.STATUS,
                             TYPE = t.TYPE,
                             ClientName = t.T_CLIENT.NAME,
                             ClientCode=t.T_CLIENT.ClientCode,
                             Car_NO=t.Car_NO,
                             RawID=t.RawID,
                             CreateUserName = t.T_SYS_USER.NAME,
                             AuditUserName = t.T_SYS_USER1.NAME,
                             Remark=t.Remark
                         };
            return source;
        }
        public IEnumerable<VInStockItem> GetVInstockItem(string StockID)
        {
            var source = from t in new BaseDAO().T_INSTOCK_ITEMs
                         where t.INSTOCK_ID.Value.ToString()==StockID
                         select new VInStockItem
                         {
                            AreaName=t.T_FLOOR.T_STOCK_AREA.AREA_NAME,
                            BAR_CODE=t.T_PRODUCT_DETAIL.BAR_CODE,
                            FLOOR_ID=t.FLOOR_ID,
                            FloorName=t.T_FLOOR.FloorName,
                            GROSS_WEIGHT=t.GROSS_WEIGHT,
                            ID=t.ID,
                            INSTOCK_ID=t.INSTOCK_ID,
                            NET_WEIGHT=t.NET_WEIGHT,
                            PACKET_QTY=t.PACKET_QTY,
                            PACKET_QTY2=t.PACKET_QTY2,
                            PackUnitName=t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT.NAME,
                            REMARK=t.REMARK,
                            StockName=t.T_FLOOR.T_STOCK_AREA.T_STOCK.STOCK_NAME,
                            StoreName=t.T_PRODUCT_DETAIL.T_PRODUCT.NAME,
                            WeightUnitName=t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT1.NAME,
                            ProductCode = t.T_PRODUCT_DETAIL.T_PRODUCT.CODE,
                            Standard = t.T_PRODUCT_DETAIL.STANDARD,
                            LotNumber = t.T_PRODUCT_DETAIL.LOT_NUMBER,
                            SubLotNumber = t.T_PRODUCT_DETAIL.SUB_LOT_NUMBER,
                            PacketNum=t.T_PRODUCT_DETAIL.PACKET_NO,
                            KeyStandard=t.T_PRODUCT_DETAIL.KeyStandard,
                            SupplyLotNumber = t.T_PRODUCT_DETAIL.SupplyLotNumber,
                            BigClass = t.T_PRODUCT_DETAIL.BigClass,
                            ClientName = t.T_INSTOCK.T_CLIENT.NAME,
                            Size=t.T_PRODUCT_DETAIL.SIZE
                         };
            return source;
        }
        public IEnumerable<VInStockItemGroup> GetVInstockItemNoFloor(string StockID)
        {
            var source = from t in new BaseDAO().T_INSTOCK_ITEMs
                         where t.INSTOCK_ID.Value.ToString() == StockID
                         group t by new
                         {
                            //BarCode=t.T_PRODUCT_DETAIL.BAR_CODE,
                            StoreName=t.T_PRODUCT_DETAIL.T_PRODUCT.NAME,
                            ProductCode = t.T_PRODUCT_DETAIL.T_PRODUCT.CODE,
                            Standard = t.T_PRODUCT_DETAIL.STANDARD,
                            LotNumber = t.T_PRODUCT_DETAIL.LOT_NUMBER,
                            SubLotNumber = t.T_PRODUCT_DETAIL.SUB_LOT_NUMBER,
                            KeyStandard = t.T_PRODUCT_DETAIL.KeyStandard,
                            SupplyLotNumber = t.T_PRODUCT_DETAIL.SupplyLotNumber,
                            BigClass = t.T_PRODUCT_DETAIL.BigClass,
                            WeightUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT1.NAME,
                            PackUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT.NAME,
                            
                         } into p
                         select new VInStockItemGroup
                         {
                            //BAR_CODE=p.Key.BarCode,
                            StoreName = p.Key.StoreName,
                            PACKET_QTYCount=p.Sum(t=>t.PACKET_QTY.Value),
                            PACKET_QTY2Count=p.Sum(t=>t.PACKET_QTY2.Value),
                            NET_WEIGHTCount=p.Sum(t=>t.NET_WEIGHT.Value),
                            GROSS_WEIGHTCount=p.Sum(t=>t.GROSS_WEIGHT.Value),
                            WeightUnitName = p.Key.WeightUnitName,
                            PackUnitName = p.Key.PackUnitName,
                            ProductCode = p.Key.ProductCode,
                            Standard = p.Key.Standard,
                            LotNumber = p.Key.LotNumber,
                            SubLotNumber = p.Key.SubLotNumber,
                            KeyStandard=p.Key.KeyStandard,
                            SupplyLotNumber = p.Key.SupplyLotNumber,
                            BigClass = p.Key.BigClass
                         };
            return source;
        }
    }

}
